/**
 * 
 */
package pagecode.pages;

import java.util.List;

import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;

import menu.DynamicMenu;
import pagecode.PageCodeBase;

import com.ibm.faces.component.html.HtmlCommandExButton;
import com.ibm.faces.component.html.HtmlScriptCollector;
import com.stefanini.pe.bbva.iivs.in.to.Menu;

/**
 * @author ocortez
 *
 */
public class LdapAcceso extends PageCodeBase {

	protected HtmlScriptCollector scriptCollector1;
	protected HtmlCommandExButton button1;
	protected HtmlForm form1;
	protected DynamicMenu dynamicMenu;
	
    public DynamicMenu getDynamicMenu() {
        if (dynamicMenu == null) {
            dynamicMenu = (DynamicMenu) getFacesContext().getApplication()
                    .createValueBinding("#{dynamicMenu}").getValue(
                            getFacesContext());
        }
        return dynamicMenu;
    }



	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}

	protected HtmlCommandExButton getButton1() {
		if (button1 == null) {
			button1 = (HtmlCommandExButton) findComponentInRoot("button1");
		}
		return button1;
	}

	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	} 
	
    @SuppressWarnings("unchecked")
	public void onPageLoadEnd(FacesContext facescontext) {
        // Type Java code to handle page load end event here
        List<Menu> opcionesMenu = (List<Menu>) this.getSession(true).getAttribute(
                "OPCIONES_MENU");
        String valida = (String) this.getRequestParam().get("valida");
//        if (valida == null) {
        if (valida.equals("true")) {
            if (opcionesMenu != null) {
                try {
                    this.getDynamicMenu().CargaMenu(opcionesMenu);
                    HttpServletResponse response = (HttpServletResponse) this
                            .getFacesContext().getExternalContext()
                            .getResponse();
                    response.sendRedirect("./IIVPPrincipal.faces");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }
}